<?php defined('IN_LK') or die('Access Denied');
/**
 * 缓存工厂类 抽象调用层
 * @author yangzhiguo 2011-03-27
 */
final class cache_factory
{
	/**
	 * chache_factory实例
	 */
	public static $cache_factory;
	
	/**
	 * cache 列表
	 */
	public static $cache_list;
	
	/**
	 * 初始化
	 */
	public function __construct()
	{
		
	}
	
	/**
	 * 获取自身实例
	 */
	public static function initialize()
	{
		if(!self::$cache_factory)
		{
			self::$cache_factory = new cache_factory;
		}
		return self::$cache_factory;
	}
	
	/**
	 * 返回非抽象实例
	 */
	public function cache($cache_type = '')
	{
		if(!$cache_type)
		{
			$cache_type = defined('CACHE_TYPE') ? CACHE_TYPE : 'file';
		}
		if(!isset(self::$cache_list[$cache_type]) || !is_object(self::$cache_list[$cache_type]))
		{
			self::$cache_list[$cache_type] = self::load($cache_type);
		}
		return self::$cache_list[$cache_type];
	}
	
	/**
	 * 加载缓存驱动
	 */
	private function load($cache_type)
	{
		$obj = null;
		switch($cache_type)
		{
			case 'memcache':
				$obj = lk::lo('cache_memcache', '', 1);
				break;
			case 'file':
			default:
				$obj = lk::lo('cache_file', '', 1);
				break;
		}
		return $obj;
	}
}